package org.redis;

import java.util.List;

import org.databind.entity.User;

import redis.clients.jedis.Jedis;

public class RedisClient {
	public static void main(String[] args) {
        //连接本地的 Redis 服务
        Jedis jedis = new Jedis("10.20.21.145",6379);
        jedis.auth("paic");
        System.out.println("连接成功");
        //查看服务是否运行
        System.out.println("服务正在运行: "+jedis.ping());
        jedis.set("runoobkey", "www.runoob.com");
        // 获取存储的数据并输出
        System.out.println("redis 存储的字符串为: "+ jedis.get("runoobkey"));
        
        jedis.lpush("site-list", "Runoob");
        jedis.lpush("site-list", "Google");
        jedis.lpush("site-list", "Taobao");
        // 获取存储的数据并输出
        List<String> list = jedis.lrange("site-list", 0 ,1);
        for(int i=0; i<list.size(); i++) {
            System.out.println("列表项为: "+list.get(i));
        }
        
        User user  = new User();
        user.setAge(16);
        user.setName("andi");
        
        jedis.set("user".getBytes(), ProtoBufUtil.serializer(user));
        
        byte[] value = jedis.get("user".getBytes());
        
        User user1 = ProtoBufUtil.deserializer(value, User.class);
        System.out.println(user1.getName());
        
        
        
    }
}
